<?php
namespace App\Controllers\Home;
use App\Libs\Home\Home as libHome;
use App\Models\Home\Home;
use \App\Libs\Cache\Redis;
/**
*	领奖
*/
class LinjiangTwo extends \App\Libs\Base\BaseAction
{
    protected function beforeRun() {
        parent::beforeRun();
        //$this->needLogin = TRUE;
    }
	
	public function execute(){
		$key = '';
		if (isset($_COOKIE[SESSION_KEY_OPEN]) && ! empty($_COOKIE[SESSION_KEY_OPEN])) {
            $key = trim($_COOKIE[SESSION_KEY_OPEN]);
		}
		
		$openid = \App\Libs\Cache\Redis::get(trim($key));
		if( empty( $openid ) ){
				return \App\Libs\Views\Json::view(1, '授权失败，请退出重新进入', null);	
		}
		$lid = (int)$this->request->get('lid');
		if( empty( $lid ) ){
			return \App\Libs\Views\Json::view(1, '页面错误，请刷新重试', null);	
		}
		
		$choujiang = Home::find(array(
			'id = :lid: and openid = :openid:',
			'bind' => array('lid'=>$lid,'openid'=>$openid),
		));
		
		if( !empty( $choujiang ) ){
			if( $choujiang->is_get == 1 ){
				return \App\Libs\Views\Json::view(1, '奖品已领取，请刷新重试！', null);
			}
			$userIndex = $choujiang->is_user;
			$jiangIndex = $choujiang->jiang;
			//存在修改 
			$choujiang->utime = date("Y-m-d H:i:s");
			$choujiang->is_get = 1;
			$choujiang->save();
			$link = self::jiangpin( $userIndex , $jiangIndex)['link'];
			return \App\Libs\Views\Json::view(0, 'success', $link);
		}else{
			return \App\Libs\Views\Json::view(1, '当前奖品不存在，请刷新重试！', null);
		}
		
	}
	
	
	public static function jiangpin( $userIndex , $jiangIndex  ){
		$arr = array(
			'1' => array(
				'1' => array( 'name'=>'冰神卡免费体验一个月','type'=>'link','link'=>'https://m.10010.com/scaffold-show/icecream-taste?WT.mc_id=zhejiang_zhejiang_517zhengshi_0515_H5_0001&utm_source=zhejiang&utm_medium=cpc&utm_term=&utm_content=jpg&utm_campaign=zhejiang_zhejiang_517zhengshi_0515_H5_0001','info'=>''),
				'2' => array( 'name'=>'优酷会员30天','type'=>'phone','info'=>'<div style="width: 80%;">优酷会员兑奖说明：<p>1、优酷土豆黄金会员（30天）将在活动结束后7个工作日内绑定到您填写的手机号码上。</p><p>2、您的手机号码就是您的会员账号，绑定成功后会有短信通知，请注意查收！。</p></div>'),
				'3' => array( 'name'=>'哈罗单车免费骑','type'=>'link','link'=>'http://pmp1.shcccoupon.com:8998/model/event/705?button=&from=singlemessage&isappinstalled=0','info'=>'')
			),
			'2' => array(
				'1' => array( 'name'=>'100元红包电子券','type'=>'phone','info'=>'<div style="width: 80%;">100元红包电子券兑奖说明：<p>1、100元红包电子券将在活动结束后7个工作日内赠送到您填写的浙江联通号码上。</p><p>2、红包电子券可在沃钱包APP中用于兑换话费、京东、天猫等抵价券。</p><p>3、若您填写的兑奖号码为非浙江联通号码则不可获赠。</p></div>'),
				'2' => array( 'name'=>'爱奇艺会员7天体验','type'=>'phone','info'=>'<div style="width: 80%;">爱奇艺VIP会员周卡兑奖说明：<p>1、爱奇艺VIP会员周卡将在活动结束后7个工作日内为您发送奖品领取短信，请根据短信中的提示进行奖品领取。</p></div>'),
				'3' => array( 'name'=>'哈罗单车免费骑','type'=>'link','link'=>'http://pmp1.shcccoupon.com:8998/model/event/705?button=&from=singlemessage&isappinstalled=0','info'=>'')
			)
		);
		return $arr[$userIndex][$jiangIndex];
		
	}
	
	
}
